<template>
  <div class="pet-info">
    <div class="box">
      <div>
        <div class="flex-b">
          <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch"
            class="flex-a input" label-width="68px">
            <el-form-item>
              <el-select v-model="queryParams.classN" placeholder="请选择分类">
                <el-option v-for="item in classList" :key="item.value" :label="item.label" :value="item.value">
                </el-option>
              </el-select>
            </el-form-item>
            <el-form-item>
              <el-select v-model="queryParams.sub" placeholder="请选择子分类">
                <el-option v-for="item in subClassList" :key="item.value" :label="item.label" :value="item.value">
                </el-option>
              </el-select>
            </el-form-item>
            <el-form-item>
              <el-select v-model="queryParams.sub" placeholder="请选择品牌">
                <el-option v-for="item in ppList" :key="item.value" :label="item.label" :value="item.value">
                </el-option>
              </el-select>
            </el-form-item>
            <el-form-item>
              <el-select v-model="queryParams.supplier" placeholder="请选择供应商">
                <el-option v-for="item in supplierList" :key="item.value" :label="item.label" :value="item.value">
                </el-option>
              </el-select>
            </el-form-item>
            <el-form-item>
              <el-select v-model="queryParams.supplier" placeholder="请选择库存状态">
                <el-option v-for="item in stateList" :key="item.value" :label="item.label" :value="item.value">
                </el-option>
              </el-select>
            </el-form-item>
            <el-form-item prop="name" class="input">
              <el-input v-model="queryParams.name" placeholder="请输入商品名称/品牌/条形码" clearable
                @keyup.enter.native="handleQuery" />
            </el-form-item>
            <el-form-item>
              <el-button type="primary" size="mini" class="btn" @click="handleQuery">查询</el-button>
              <el-button type="warning" size="mini" class="btn" @click="handleExport"
                v-hasPermi="['pet:prodInfo:export']">导出</el-button>
            </el-form-item>
          </el-form>
        </div>
        <div>
          <el-table :data="prodInfoList">
            <el-table-column label="商品图片" align="center" prop="">
              <template slot-scope="scope">
                <img :src="scope.row.url" style="width:50%" alt="">
              </template>
            </el-table-column>
            <el-table-column label="商品名称" align="center" prop="name" />
            <el-table-column label="条形码" align="center" prop="name" />
            <el-table-column label="品牌名" align="center" prop="brand" />
            <el-table-column label="规格型号" align="center" prop="brand" />
            <el-table-column label="单位" align="center" prop="brand" />
            <!-- <el-table-column label="标准进货价" align="center" prop="retPrice" />
            <el-table-column label="平均成本价" sortable align="center" prop="memPrice" />
            <el-table-column label="零售价" sortable align="center" prop="alert" /> -->
            <el-table-column label="现有库存数" sortable align="center" prop="alert" />
            <!-- <el-table-column label="销售比" sortable align="center" prop="alert" /> -->
            <!-- <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
              <template slot-scope="scope">
                <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
                  v-hasPermi="['pet:prodInfo:edit']">修改</el-button>
                <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
                  v-hasPermi="['pet:prodInfo:remove']">删除</el-button>
              </template>
            </el-table-column> -->
          </el-table>
        </div>
        <pagination :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
          @pagination="getList" />
      </div>
    </div>
  </div>
</template>

<script>
import { listProdInfo, getProdInfo, delProdInfo, addProdInfo, updateProdInfo } from "@/api/pet/prodInfo";
export default {
  name: "PetInfo",
  components: {

  },
  data() {
    return {
      pzList: [],
      subClassList: [],
      classList: [
        {
          value: 0,
          label: '药品'
        },
        {
          value: 1,
          label: '食品'
        },
        {
          value: 3,
          label: '其他'
        },
        {
          value: 4,
          label: '用品'
        },
      ],
      ppList: [
        {
          value: 0,
          label: '比瑞吉'
        },
        {
          value: 1,
          label: '迈德试'
        },
        {
          value: 3,
          label: '雪貂'
        },
        {
          value: 4,
          label: '小宠'
        },
      ],
      supplierList: [],
      stateList: [
        {
          value: 0,
          label: '正常库存'
        },
        {
          value: 1,
          label: '库存预警状态'
        },
        {
          value: 3,
          label: '无库存状态'
        },
      ],
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 商品信息表格数据
      prodInfoList: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        name: null,
        varId: null,
        inPrice: null,
        outPrice: null,
        sex: null,
        petColor: null,
        weight: null,
        high: null,
        date: null,
        state: null,
        inDate: null,
        source: null,
        picture: null,
        updateUser: null,
        createUser: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    getList() {
      this.loading = true;
      listProdInfo(this.queryParams).then(response => {
        this.prodInfoList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        name: null,
        varId: null,
        inPrice: null,
        outPrice: null,
        sex: null,
        petColor: null,
        weight: null,
        high: null,
        date: null,
        state: null,
        inDate: null,
        source: null,
        remark: null,
        picture: null,
        updateUser: null,
        updateTime: null,
        createUser: null,
        createTime: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.$router.push({ path: '/goods/living', query: {} })
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getPetInfo(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改活体信息";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updatePetInfo(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addPetInfo(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除活体信息编号为"' + ids + '"的数据项？').then(function () {
        return delPetInfo(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => { });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('pet/petInfo/export', {
        ...this.queryParams
      }, `petInfo_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
